package com.zhongke.cotrun.mapper;

import com.zhongke.cotrun.model.pojo.CompanyInfo;
import com.zhongke.cotrun.model.pojo.CompanyInfoVo;
import com.zhongke.cotrun.model.pojo.UserInforCompany;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CompanyInfoMapper {
    @Select("select * from company_info")
    List<CompanyInfo> selectAll();

    /**
     * 保存
     * @param companyInfo
     * @return
     */
    @Insert("INSERT INTO `cotrun`.`company_info` (`link_user_id`,`company_name`,`company_code`,`province`,`city`,`company_email`,`company_providers`,`company_type`,`business_license`,`company_logo`,`remarks`) VALUES" +
            "(#{linkUserId},#{companyName},#{companyCode},#{province},#{city},#{companyEmail},#{companyProviders},#{companyType},#{businessLicense},#{companyLogo},#{remarks})")
    boolean saveCompanyInfo(CompanyInfo companyInfo);

    /**
     * 保存
     * @param companyInfo
     * @return
     */
    @Insert("INSERT INTO `cotrun`.`company_info` (`link_user_id`,`company_name`,`company_code`,`province`,`city`,`company_email`,`company_providers`,`company_type`,`business_license`,`company_logo`,`remarks`) VALUES" +
            "(#{userId},#{companyName},#{companyCode},#{province},#{city},#{companyEmail},#{companyProviders},#{companyType},#{businessLicense},#{companyLogo},#{remarks})")
    boolean saveCompanyInfoByUser(UserInforCompany companyInfo);
    /**
     * 根据id查看详情
     * @param id
     * @return
     */
    @Select("select * from company_info where company_id = #{id}")
    CompanyInfoVo selectCompanyInfoById(@Param("id") Long id);

    /**
     * 根据用户id查看详情
     * @param id
     * @return
     */
    @Select("select * from company_info where link_user_id = #{id} limit 1")
    CompanyInfoVo selectCompanyInfoByUserId(@Param("id") Integer id);

    /**
     * 修改
     * @param companyInfo
     * @return
     */
    @Update("UPDATE `cotrun`.`company_info` SET " +
            "`link_user_id`=#{linkUserId}, `company_name`=#{companyName}, `company_code`=#{companyCode}, `province`=#{province}, `city`=#{city}, `company_email`=#{companyEmail}, " +
            "`company_providers`=#{companyProviders}, `company_type`=#{companyType}, `business_license`=#{businessLicense}, `company_logo`=#{companyLogo},`audit_status`=#{auditStatus} " +
            "WHERE `company_id`=#{companyId}")
    boolean updateCompanyInfo(CompanyInfo companyInfo);
    /**
     * 修改
     * @param companyInfo
     * @return
     */
//    @Update("UPDATE `cotrun`.`company_info` SET " +
//            "`link_user_id`=#{userId}, `company_name`=#{companyName}, `company_code`=#{companyCode}, `province`=#{province}, `city`=#{city}, `company_email`=#{companyEmail}, " +
//            "`company_providers`=#{companyProviders}, `company_type`=#{companyType}, `business_license`=#{businessLicense}, `company_logo`=#{companyLogo},`audit_status`=#{auditStatus} " +
//            "WHERE `company_id`=#{companyId}")
    boolean updateCompanyInfoByUser(UserInforCompany companyInfo);

    /**
     * 审核通过
     * @param companyId
     * @param userName
     * @return
     */
    @Update("update company_info set audit_status = 1,audit_user = #{userName},audit_time = now() where company_id = #{companyId}")
    boolean approvalPass(Long companyId, String userName);

    /**
     * 审核驳回
     * @param companyId
     * @param userName
     * @param auditOpinion
     * @return
     */
    @Update("update company_info set audit_status = 2,audit_user = #{userName},audit_time = now(),audit_opinion = #{auditOpinion} where company_id = #{companyId}")
    boolean approvalRejected(Long companyId, String userName, String auditOpinion);
}
